package com.jsj.controller;

import com.jsj.domain.SubmissionTopic;
import com.jsj.domain.vo.TopicSubmissionVo;
import com.jsj.service.ISubmissionTopicService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 作业Controller
 */
@RestController
@RequestMapping("/topic")
public class SubmissionTopicController extends BaseController {
    @Autowired
    private ISubmissionTopicService submissionTopicService;

    /**
     * 查询作业提交
     */
    @RequestMapping(value = "/querySubmissionTopicById", method = {RequestMethod.POST})
    @ResponseBody
    @PreAuthorize("@ss.hasAnyRoles('student,teacher,admin')")
    public SubmissionTopic querySubmissionTopicById(@RequestBody int id) {
        return submissionTopicService.querySubmissionTopicById(id);
    }

    /**
     * 查询作业学生提交
     */
    @RequestMapping(value = "/querySubmissionTopic", method = {RequestMethod.POST})
    @ResponseBody
    @PreAuthorize("@ss.hasAnyRoles('teacher,admin')")
    public List<TopicSubmissionVo> querySubmissionTopic(@RequestBody int topicId) {
        return submissionTopicService.querySubmissionTopic(topicId);
    }

    /**
     * 作业提交
     */
    @RequestMapping(value = "/insertSubmissionTopic", method = {RequestMethod.POST})
    @ResponseBody
    @PreAuthorize("@ss.hasAnyRoles('teacher,admin')")
    public AjaxResult insertSubmissionTopic(@RequestBody SubmissionTopic submissionTopic) {
        if (submissionTopicService.insertSubmissionTopic(submissionTopic) == 0) {
            return AjaxResult.error("提交失败");
        }
        return AjaxResult.success("提交成功");
    }

    /**
     * 删除作业提交
     */
    @RequestMapping(value = "/deleteSubmissionTopic", method = {RequestMethod.POST})
    @ResponseBody
    @PreAuthorize("@ss.hasAnyRoles('teacher,admin')")
    public AjaxResult deleteSubmissionTopic(@RequestBody int id) {
        if (submissionTopicService.deleteSubmissionTopic(id) == 0) {
            return AjaxResult.error("删除失败");
        }
        return AjaxResult.success("删除成功");
    }

}
